package com.shadow.demo.component.variable;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/variable")
public class VariablePageController {

    private final VariableService variableService;

    VariablePageController(VariableService variableService) {
        this.variableService = variableService;
    }

    /**
     * 分页查询数据字典.
     **/
    @GetMapping("/list")
    public String list(final ModelMap model) {
        setCommonModelMap(model);
        return "component/variable/list";
    }

    /**
     * 新增数据字典初始页面.
     **/
    @GetMapping("/add")
    public String add(final ModelMap model) {
        setCommonModelMap(model);
        return "component/variable/add";
    }

    private void setCommonModelMap(final ModelMap modelMap) {
        modelMap.addAttribute("parentList", variableService.getParentAuthList(true));
    }
}
